<?php
/**
 * 
 * Modelo de categoria de script
 * @author natanael
 * 
 */
class Mcategoria extends Model{
    
	private $_nameTable = "SCT_Categoria";
	
    public function __construct()
    {
        parent::Model();
	    $this->load->database();
    }
    
    public function loadCategoriaFrom($start = false, $offset = false, $sortname = false, $sortorder = false)
    {
            
           if($offset != false)
		       $this->db->limit($offset, $start);

		   if($sortname != false && $sortorder != false) 
			    $this->db->order_by($sortname, $sortorder);
				  
		    $result = $this->db->get_where($this->_nameTable);
	
			return $this->GetArrayFromQueryResult($result);
			
     }
       
     public function loadRegistroByWhere($where)
     {
            $result = $this->db->get_where($this->_nameTable, $where);
            return $this->GetArrayFromQueryResult($result);
     }
       
     public function LoadRegistroById($id) 
	 {
		   $qresult = $this->db->get_where($this->_nameTable, array('idCategoria' => $id));		
		
		   if ($qresult->num_rows() == 0)
		   {
			 return false;
		   }	
           
		   return new SCT_Categoria($qresult->row());
	  }
       
      private function GetArrayFromQueryResult($result)
      {
           if ($result->num_rows() == 0)
				      return false;
	
			 $data_arr = array();
	
			foreach ($result->result() as $record) {
				$data_arr[] = new SCT_Categoria($record);
		    }
	
			return $data_arr;
      }
       
      public function addRegistro($data)
      {
          if ($this->db->insert($this->_nameTable,$data)) 
             return true;
             
            return false;   
         
      }
       
      public function updateRegistro($data, $where)
      {
          if ($this->db->update($this->_nameTable,$data, $where))
             return true;

             return false; 
      
      }
       
      public function daleteRegistro($where)
      {
           if($this->db->delete($this->_nameTable, $where))
              return true;
              
             return false;      
      }

}

class SCT_Categoria{
      
      private $_idCategoria = 0;
      private $_categoria = "";
      private $_descCategoria = "";

      public function __construct($ojt)
      {
         $this->setIdCategoria($ojt->idCategoria);
         $this->setCategoria($ojt->categoria);
         $this->setDescCategoria($ojt->descCategoria);
      }
      
      public function getIdCategoria()
      {
        return $this->_idCategoria;
      }
      
      public function setIdCategoria($ojt)
      {
        $this->_idCategoria = $ojt;
      }
      
      public function getCategoria()
      {
        return $this->_categoria;
      }
      
      public function setCategoria($ojt)
      {
        $this->_categoria = $ojt;
      }
      
      public function getDescCategoria()
      {
        return $this->_descCategoria;
      }
      
      public function setDescCategoria($ojt)
      {
        $this->_descCategoria = $ojt;
      }
}